import asyncio
from concurrent.futures import ThreadPoolExecutor


# 定义一个异步函数
async def async_function():
    print("Starting async function")
    await asyncio.sleep(1)  # 模拟异步操作
    print("Finished async function")
    return "Result from async function"

# 定义一个同步函数，在其中调用异步函数
def sync_function():
    print("Starting sync function")

    # 使用线程池执行器来运行异步函数并获取结果
    loop = asyncio.get_event_loop()
    asyncio.run_coroutine_threadsafe(async_function, loop)

    # print(f"Result received in sync function: {result}")
    print("Finished sync function")


# 主协程函数
async def main():
    print("Starting main coroutine")
    sync_function()
    print("Main coroutine continues")

# 运行主协程
asyncio.run(main())
